﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net.Mail;


namespace QUANLIBANHANG.GUI
{
    public partial class usControlRespond : UserControl
    {
        string data;
        public usControlRespond()
        {
            InitializeComponent();
        }

        private void btnSendEmail_Click(object sender, EventArgs e)
        {
            MailMessage _email = new MailMessage(txtUser.Text, "Namyamiuit@gmail.com", txtTitle.Text, txtBody.Text);
            SmtpClient _client = new SmtpClient("smtp.gmail.com");
            _client.Port = 587;
            _client.Credentials = new System.Net.NetworkCredential(txtUser.Text, txtPass.Text);
            _client.EnableSsl = true;
            if (data!=null)
            {
                Attachment _data = new Attachment(data);
                _email.Attachments.Add(_data);
            }
            _client.Send(_email);
            MessageBox.Show("Bạn đã gửi thành công","Thông báo");
        }

        private void usControlRespond_Load(object sender, EventArgs e)
        {

        }

        private void btnAttach_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Data File |*.rar;*.jpg;*.png;";
            if (open.ShowDialog()==DialogResult.OK)
            {
                data = open.FileName;
            }
        }
    }
}
